<template>
  <div class="contain">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="标题" prop="sender">
        <el-input v-model="query.title" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="盘源委托人" align="center" prop="bailor"></el-table-column>
      <el-table-column label="投放类型" align="center" prop="putType"></el-table-column>
      <el-table-column label="名称" align="center" prop="name"></el-table-column>
      <el-table-column label="联系方式" align="center" prop="phone"></el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime"></el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime"></el-table-column>
      <el-table-column label="审核状态">
        <template slot-scope="scope">
            <span>{{ scope.row.audit == 0 ? '待审核' : scope.row.audit == 1 ? '审核通过' : '审核拒绝' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="creatItem('edit', scope.row)">审核</el-button>
          <!-- <el-button v-hasPermi="['enterpriseWechat:edit']" size="mini" type="text" @click="deleteItem(scope.row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 编辑表单 -->
    <el-dialog :title="formTtile == 'creat' ? '添加' : '编辑'" :visible.sync="editFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-width="90px" label-position="right">
        <el-form-item label="姓名" prop="name">
          <el-input class="input" v-model="form.name" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="联系方式" prop="phone">
          <el-input class="input" v-model="form.phone" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="盘源委托人" prop="bailor">
          <el-input class="input" v-model="form.bailor" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="投放类型" prop="putType">
          <el-input class="input" v-model="form.putType" placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="审核状态" prop="audit">
          <!-- <el-input class="input" v-model="form.audit" placeholder="请输入" clearable  /> -->
          <el-radio-group v-model="form.audit" size="small">
            <el-radio :label="0" border>待审核</el-radio>
            <el-radio :label="1" border>审核通过</el-radio>
            <el-radio :label="2" border>审核拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- <el-form-item label="是否删除" prop="delFlag">
          <el-switch  v-model="form.delFlag" active-value="1" inactive-value="0"></el-switch>
        </el-form-item> -->
        <el-form-item label=" ">
          <el-button type="primary" @click="submit()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getApplyEntrant, updateApplyEntrant } from "@/api/eh-api";
export default {
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      // 查询参数
      query: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
      },
      list:[],
      editFormShow:false,
      formTtile:'creat',
      form:{
        "audit": 0,
        "bailor": "",
        "createTime": "",
        // "delFlag": "",
        "id": 0,
        "name": "",
        "phone": "",
        "putType": "",
        "updateTime": ""
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      getApplyEntrant(this.query)
        .then(({ rows, total }) => {
          this.list = rows;
          this.total = parseInt(total);
          this.loading = false;
          this.ids = [];
        })
        .catch(() => {
          this.loading = false;
        });
    },
    /**
     * 添加
     */
    creatItem:function(title,item) {
      this.formTtile = title
      this.editFormShow = true
      if( title == 'edit' ){
        this.form = item
      }else{
        this.form = {}
      }
    },
    /**
     * 提交表单
     */
    submit:function(params) {
        console.log( this.form )
        if( this.formTtile == 'creat' ){
          
        }else{
          updateApplyEntrant(this.form).then( res => {
              if( res.code == 200 ){
                this.$message({
                  message: '编辑成功',
                  type: 'success'
                });
                this.getList();
              }else{
                this.$message.error(res.msg);
              }
            })
        }
        this.editFormShow = false
    },
    /**
     * 删除
     */
    deleteItem:function(rows) {
        console.log(rows)
        deleteMessage({
          newsId:rows.newsId
        }).then( res => {
            if( res.code == 200 ){
              this.$message({
                message: '删除成功',
                type: 'success'
              });
              this.getList();
            }else{
              this.$message.error(res.msg);
            }
        })
    },
    /**
     * 统一路由
     */
    route(row) {
      console.log(row)
      this.$router.push({ path: 'creat', query: { id:row.id } })
    },
  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}
</style>
